using System;
using System.Net;
using System.Windows.Media;
using ClientLauncher.Src.WPFUtils;
using Game500.ClientServerCommon.Src;

namespace ClientLauncher.Src.ViewModels
{
  public class GameInfoViewModel
  {
    private readonly NetworkGameInfo myInfo;
    private readonly Guid myMapGuid;
    private readonly BaseMapManager myMapManager;

    public GameInfoViewModel(NetworkGameInfo info, BaseMapManager mapManager)
    {
      myInfo = info;
      myMapManager = mapManager;
      myMapGuid = info.MapId;
    }

    public GameInfoViewModel(Map info)
    {
      myMapGuid = info.MapId;
    }

    public ImageSource Thumbnail
    {
      get { return myMapManager.GetThumbnail(myMapGuid).ToBitmapImage(); }
    }

    public int MaxPlayers
    {
      get { return myInfo.MaxPlayers; }
    }

    public int ActivePlayers
    {
      get { return myInfo.ActivePlayers; }
    }

    public string SceneName
    {
      get
      {
        string name = myMapManager.GetMapName(myInfo.MapId);
        int w = myMapManager.GetMapWidth(myInfo.MapId);
        int h = myMapManager.GetMapHeight(myInfo.MapId);
        return name + ". " + w + "x" + h;
      }
    }

    public string GameMessage
    {
      get { return myInfo.GameMessage; }
    }

    public string PlayersQuantityInfo
    {
      get { return myInfo.ActivePlayers + "/" + myInfo.MaxPlayers; }
    }

    public IPEndPoint ServerAddress
    {
      get { return myInfo.ServerAddress; }
    }
  }
}